var kaiquan = {
	btn: $("#kaiquan"),
	getAsciiString: function(src) {
		var str = "0x";
		for(var i = 0; i < src.length; i++) {
			str = str + "" + src.charCodeAt(i).toString(16);
		}
		return str;
	},
	click: function() {
		if($("#kaiquan").hasClass("active")) return;
		var content = $("#SubmitChoiceHtml").html();
		AlertView.layer.open("出加密拳", content, function() {
			AlertView.SubmitChoiceHtml.init(kaiquan);
			var gameChoice = AlertView.SubmitChoiceHtml.getSelecter();
			gameChoice.val(GameView.param.choice);
			var input = AlertView.SubmitChoiceHtml.getInput();
			input.val(GameView.param.secret);
		}, {
			area: ['30rem', '17rem']
		});
	},
	submitClick: function() {
		AlertView.layer.loading("正在提交中(大约1分钟,请勿关闭)...");
		GameView.param.choice = AlertView.SubmitChoiceHtml.getSelecter().val();
		GameView.param.secret = AlertView.SubmitChoiceHtml.getInput().val();
		var str = kaiquan.getAsciiString(GameView.param.secret);
		BC.do("reveal", {
			hashId: "0x"+GameView.param.gameId,
			choice: GameView.param.choice,
			secret: str
		}).then(kaiquan.result).catch(function(err){
			console.log(err);
			AlertView.layer.alert("错误", err.msg);
		});
	},
	result: function(result) {
		layer.closeAll();
		if(result.logs.length > 0) {
			$("#kaiquan").addClass("active");
			$("#kaiquan").html("已开拳");
			AlertView.layer.alert("成功", "您已成功开拳，等待对方出完拳后，系统将自动结算。");
		}
	},
	setParam:function(param){
		kaiquan.param = param;
		var html = template("kaiquanTmp",param);
		$("tr.kaiquantr").html(html);
		$("#kaiquan").on("clikc",function(){
			kaiquan.query().then(function(result){
				kaiquan.click();
			}).catch(function(err){
				AlertView.layer.alert("错误", err.msg);
			});
		});
	},
	query: function() {
		var p = BC.do("canAction", {
			hashId: "0x"+GameView.param.gameId,
			oper: 'r'
		});
		return p;
	},
	init: function() {
	}
};